var e = wx.createCanvasContext("visitingCardCanvas");

Page({
    data: {},
    onLoad: function(e) {
        console.log(e), this.setData({
            typeName: e.typeName,
            name: e.name,
            position: e.position,
            address: e.address,
            phone: e.phone,
            email: e.email,
            userIcon: e.userIcon
        }), this.drawPic();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    drawPic: function() {
        var t = this.data, i = wx.getSystemInfoSync().windowWidth;
        "1" == t.typeName ? (e.drawImage("/images/modelN1.png", 0, 0, i, .6 * i), e.save(), 
        e.beginPath(), e.arc(40, 40, 30, 0, 2 * Math.PI), e.closePath(), e.clip(), e.drawImage(t.userIcon, 10, 10, 60, 60), 
        e.restore(), e.setFontSize(18), e.fillText(t.name, 80, 35), e.setFontSize(15), e.fillText(t.position, 80, 55)) : (e.drawImage("/images/modelN2.jpg", 0, 0, i, .6 * i), 
        e.save(), e.beginPath(), e.arc(i - 50, 50, 30, 0, 2 * Math.PI), e.closePath(), e.clip(), 
        e.drawImage(t.userIcon, i - 80, 20, 60, 60), e.restore(), e.setFontSize(18), e.setTextAlign("right"), 
        e.fillText(t.name, i - 90, 45), e.setFontSize(15), e.setTextAlign("right"), e.fillText(t.position, i - 90, 65)), 
        e.setTextAlign("left"), e.setFontSize(15), e.fillText("地址：" + t.address, 15, 140), 
        e.setFontSize(15), e.fillText("电话：" + t.phone, 15, 170), e.setFontSize(15), e.fillText("邮箱：" + t.email, 15, 200), 
        e.draw();
    },
    saveVisitingCard: function() {
        var e = wx.getSystemInfoSync().windowWidth;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: e,
            height: .6 * e,
            destWidth: 2 * e,
            destHeight: .6 * e * 2,
            canvasId: "visitingCardCanvas",
            success: function(e) {
                wx.saveImageToPhotosAlbum({
                    filePath: e.tempFilePath
                }), wx.hideLoading(), wx.showToast({
                    title: "保存成功！",
                    icon: "success"
                }), setTimeout(function() {
                    wx.navigateBack({});
                }, 1e3);
            }
        });
    },
    toSharePic: function() {
        var e = wx.getSystemInfoSync().windowWidth;
        this.data;
        wx.canvasToTempFilePath({
            x: 0,
            y: 0,
            width: e,
            height: .6 * e,
            destWidth: 2 * e,
            destHeight: 1.2 * e,
            canvasId: "visitingCardCanvas",
            success: function(e) {
                wx.navigateTo({
                    url: "/pages/sharePhoto/sharePhoto?imageUrl=" + e.tempFilePath
                });
            }
        });
    }
});